import {
  Controller,
  Get,
  Post,
  Body,
  Put,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { CarService } from './car.service';
import { CreateCarDto } from './dto/create-car.dto';
import { UpdateCarDto } from './dto/update-car.dto';
import { ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';

@Controller('car')
@ApiTags('车辆管理')
export class CarController {
  constructor(private readonly carService: CarService) {}

  @Post()
  @ApiOperation({
    description: '添加车辆',
    summary: '添加车辆',
  })
  create(@Body() createCarDto: CreateCarDto) {
    return this.carService.create(createCarDto);
  }

  // @Get()
  // @ApiOperation({
  //   description: '查询全部车辆',
  //   summary: '查询全部车辆',
  // })
  // findAll() {
  //   return this.carService.findAll();
  // }

  @Get(':id')
  @ApiParam({
    name: 'id',
    description: '车辆id',
  })
  @ApiOperation({
    description: '查询单个车辆',
    summary: '查询单个车辆',
  })
  findOne(@Param('id') id: string) {
    return this.carService.findOne(+id);
  }

  @Get()
  @ApiOperation({
    summary: '分页查询',
    description: '分页查管理员所在地区的用户信息',
  })
  @ApiQuery({ name: 'pageSize', description: '数据条数', required: true })
  @ApiQuery({ name: 'currentPage', description: '当前页码', required: true })
  @ApiQuery({ name: 'city', description: '城市', required: true })
  @ApiQuery({ name: 'keywords', description: '关键词', required: false })
  skipFind(
    @Query('currentPage') currentPage,
    @Query('pageSize') pageSize,
    @Query('city') city,
    @Query('keywords') keywords,
  ) {
    return this.carService.skipFind(+currentPage, +pageSize, city, keywords);
  }

  @Put()
  @ApiOperation({
    description: '修改车辆信息',
    summary: '修改车辆信息',
  })
  update(@Body() updateCarDto: UpdateCarDto) {
    return this.carService.update(updateCarDto);
  }

  @Delete('/delete')
  @ApiOperation({
    description: '删除车辆',
    summary: '删除车辆',
  })
  remove(@Body() ids: number[]) {
    return this.carService.remove(ids);
  }
}
